/*
 * @brief:
 * @Author: TzzzT
 * @Date: 2022-09-24 13:46:12
 * @LastEditTime: 2023-05-17 23:05:19
 * @LastEditors: TzzzT
 */
#pragma once

typedef enum bc260_stage_e
{
  INIT_BC260,
  FIND_NET_BC260,
  CHECK_NET_BC260,
  OPENING_SERVR_BC260,
  CONNECTTED_BC260,
} bc260_stage_t;

typedef enum open_state_e
{
  SEND_OPEN,
  CLOSE_OPEN,
  WAIT_OPEN_RESULT,
} open_state_t;

#define TARGET_BAUDRATE 115200
#define DEFAULT_BAUDRATE 9600

typedef void (*inform_cb_t)(uint8_t *, uint16_t);
typedef void (*net_up_cb_t)(uint8_t);
typedef void (*net_down_cb_t)(uint8_t);
typedef struct bc260_s
{
  uint32_t current_baud;
  uint32_t target_baud;

  QueueHandle_t inform_queue;
  QueueHandle_t resp_queue;

  bc260_stage_t stage;
  open_state_t open_state;
  uint8_t reopen_flag;
  uint8_t wait70s_flag;
  uint8_t rst_flag;
  inform_cb_t inform_cb;
  net_up_cb_t net_up_cb;
  net_down_cb_t net_down_cb;
} bc260_t;

#define BC260_INFORM_Q_LENGTH 10
#define BC260_RESP_Q_LENGTH 10

typedef enum bc260_resp_class_e
{
  IP_RESP,
}bc260_resp_class_t;

void bc260_init(inform_cb_t _inform_cb, net_up_cb_t _up_cb, net_down_cb_t _down_cb);
uint8_t bc_open_server_socket(void);
uint8_t bc_show_something(uint8_t idx);
void bc_send_package_to_server(char *package, size_t len);
